#pragma once

#include once "winapifamily.bi"

#define _USBSCAN_H_
const MAX_NUM_PIPES = 8
const BULKIN_FLAG = &h80

type _DRV_VERSION
	major as ulong
	minor as ulong
	internal as ulong
end type

type DRV_VERSION as _DRV_VERSION
type PDRV_VERSION as _DRV_VERSION ptr

type _IO_BLOCK
	uOffset as ulong
	uLength as ulong
	pbyData as PUCHAR
	uIndex as ulong
end type

type IO_BLOCK as _IO_BLOCK
type PIO_BLOCK as _IO_BLOCK ptr

type _IO_BLOCK_EX
	uOffset as ulong
	uLength as ulong
	pbyData as PUCHAR
	uIndex as ulong
	bRequest as UCHAR
	bmRequestType as UCHAR
	fTransferDirectionIn as UCHAR
end type

type IO_BLOCK_EX as _IO_BLOCK_EX
type PIO_BLOCK_EX as _IO_BLOCK_EX ptr

type _CHANNEL_INFO
	EventChannelSize as ulong
	uReadDataAlignment as ulong
	uWriteDataAlignment as ulong
end type

type CHANNEL_INFO as _CHANNEL_INFO
type PCHANNEL_INFO as _CHANNEL_INFO ptr

type PIPE_TYPE as long
enum
	EVENT_PIPE
	READ_DATA_PIPE
	WRITE_DATA_PIPE
	ALL_PIPE
end enum

type _USBSCAN_GET_DESCRIPTOR
	DescriptorType as UCHAR
	Index as UCHAR
	LanguageId as USHORT
end type

type USBSCAN_GET_DESCRIPTOR as _USBSCAN_GET_DESCRIPTOR
type PUSBSCAN_GET_DESCRIPTOR as _USBSCAN_GET_DESCRIPTOR ptr

type _DEVICE_DESCRIPTOR
	usVendorId as USHORT
	usProductId as USHORT
	usBcdDevice as USHORT
	usLanguageId as USHORT
end type

type DEVICE_DESCRIPTOR as _DEVICE_DESCRIPTOR
type PDEVICE_DESCRIPTOR as _DEVICE_DESCRIPTOR ptr

type _RAW_PIPE_TYPE as long
enum
	USBSCAN_PIPE_CONTROL
	USBSCAN_PIPE_ISOCHRONOUS
	USBSCAN_PIPE_BULK
	USBSCAN_PIPE_INTERRUPT
end enum

type RAW_PIPE_TYPE as _RAW_PIPE_TYPE

type _USBSCAN_PIPE_INFORMATION
	MaximumPacketSize as USHORT
	EndpointAddress as UCHAR
	Interval as UCHAR
	PipeType as RAW_PIPE_TYPE
end type

type USBSCAN_PIPE_INFORMATION as _USBSCAN_PIPE_INFORMATION
type PUSBSCAN_PIPE_INFORMATION as _USBSCAN_PIPE_INFORMATION ptr

type _USBSCAN_PIPE_CONFIGURATION
	NumberOfPipes as ULONG
	PipeInfo(0 to 7) as USBSCAN_PIPE_INFORMATION
end type

type USBSCAN_PIPE_CONFIGURATION as _USBSCAN_PIPE_CONFIGURATION
type PUSBSCAN_PIPE_CONFIGURATION as _USBSCAN_PIPE_CONFIGURATION ptr

type _USBSCAN_TIMEOUT
	TimeoutRead as ULONG
	TimeoutWrite as ULONG
	TimeoutEvent as ULONG
end type

type USBSCAN_TIMEOUT as _USBSCAN_TIMEOUT
type PUSBSCAN_TIMEOUT as _USBSCAN_TIMEOUT ptr
const FILE_DEVICE_USB_SCAN = &h8000
const IOCTL_INDEX = &h0800
const ALL = ALL_PIPE
#define IOCTL_ABORT_PIPE IOCTL_CANCEL_IO
#define IOCTL_GET_VERSION CTL_CODE(FILE_DEVICE_USB_SCAN, IOCTL_INDEX, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_CANCEL_IO CTL_CODE(FILE_DEVICE_USB_SCAN, IOCTL_INDEX + 1, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_WAIT_ON_DEVICE_EVENT CTL_CODE(FILE_DEVICE_USB_SCAN, IOCTL_INDEX + 2, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_READ_REGISTERS CTL_CODE(FILE_DEVICE_USB_SCAN, IOCTL_INDEX + 3, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_WRITE_REGISTERS CTL_CODE(FILE_DEVICE_USB_SCAN, IOCTL_INDEX + 4, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_GET_CHANNEL_ALIGN_RQST CTL_CODE(FILE_DEVICE_USB_SCAN, IOCTL_INDEX + 5, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_GET_DEVICE_DESCRIPTOR CTL_CODE(FILE_DEVICE_USB_SCAN, IOCTL_INDEX + 6, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_RESET_PIPE CTL_CODE(FILE_DEVICE_USB_SCAN, IOCTL_INDEX + 7, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_GET_USB_DESCRIPTOR CTL_CODE(FILE_DEVICE_USB_SCAN, IOCTL_INDEX + 8, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_SEND_USB_REQUEST CTL_CODE(FILE_DEVICE_USB_SCAN, IOCTL_INDEX + 9, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_GET_PIPE_CONFIGURATION CTL_CODE(FILE_DEVICE_USB_SCAN, IOCTL_INDEX + 10, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_SET_TIMEOUT CTL_CODE(FILE_DEVICE_USB_SCAN, IOCTL_INDEX + 11, METHOD_BUFFERED, FILE_ANY_ACCESS)
